<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>登录</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <link rel="stylesheet" th:href="@{/lib/weui.min.css}">
    <link rel="stylesheet" th:href="@{/css/jquery-weui.css}">
    <link rel="stylesheet" th:href="@{/css/demos.css}">
    <script th:inline="javascript">
        /*<![CDATA[*/
        var tokenParam = [[${tokenParam}]];

    </script>
</head>
<body>
<header class='demos-header'>
    <h1 class="demos-title">核销商家券</h1>
</header>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">商家券号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="couponCode" type="text"  placeholder="商家券号">
        </div>
    </div>
    <div class="weui-cell">
    </div>
    <div class="weui-msg">
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:save();" class="weui-btn weui-btn_primary">确定</a>
            </p>
        </div>
    </div>
</div>
</body>
<script th:src="@{/lib/jquery-2.1.4.js}"></script>
<script th:src="@{/lib/fastclick.js}"></script>
<script th:src="@{/js/jquery-weui.js}"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
        console.log(tokenParam)
    });
    function save(){
        var couponCode = $("#couponCode").val();
        if(couponCode == null || couponCode == "" || couponCode == undefined){
            $.toast("商家券号不能为空！", "cancel");
            return
        }

        $.get("/coupon/offcialAccount/pay",{couponCode:couponCode,tokenParam:tokenParam},function(res){
            if(res.code == 200){
                $.toast("核销成功", "ok");
            }else{
                var message = res.message;
                try{
                    var parse = JSON.parse(message);
                    var newVar = parse.message;
                    $.toast(newVar, "cancel");
                }catch (e) {
                    $.toast(message, "cancel");
                }
                /*var parse = JSON.parse(message);
                if(parse!=""||parse!=null){
                    var newVar = parse.message;
                    $.toast(newVar, "cancel");
                }else {
                    $.toast(message, "cancel");
                }*/

            }
        })
    }
    /*function setText(number){

        number = number-1;
        if(number > 0){
            $("#smsId").text(number +"(秒)")
            $("#smsId").attr("disabled","disabled");
            setTimeout("setText("+number+")",1000);
        }else{
            $("#smsId").text("获取验证码")
            $("#smsId").removeAttr("disabled")
        }
    }
    function savePhone(){
        var phone = $("#phone").val();
        var code = $("#code").val();
        var openId = $("#openId").val();
        var appId = $("#appId").val();
        $.post("/center/savePhone",{phone:phone,code:code,openId:openId,appId:appId},function(res){
            if(res.code == 200){
                window.location.href="/center/regist";
            }else{
                $.toast(res.message, "forbidden");
            }
        })
    }*/
</script>
</html>